class Solution {
public:
    int longestConsecutive(vector<int>& nums)
    {
        unordered_map<int, int > hash;
        for (auto x : nums)
        {
            hash[x] = 1;
        }
        int count = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            if (!hash.count(nums[i] - 1))
            {
                int cur = nums[i];
                while (hash.count(cur + 1))
                {
                    cur++;
                }
                count = max(count, cur - nums[i] + 1);
            }
        }
        return count;
    }
};